function getUrlData(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

function getShareinfo() {
    var result = "";
    var url = magic_config.urlPrefix + "GroupbuyService/getgroupbuyshareinfo";
    data = {
        lTeamId: getUrlData("lTeamId")
    };
    $.ajax({
        url: url,
        type: 'post',
        data: data,
        async: false,
        dataType: 'json',
        success: function(res) {
            var nCode = res.return.nCode;
            if (nCode === 0) {
                result = res.response;
                config_share(result);
            } else {
                console.log(res);
            }
        },
        error: function(res) {
            console.log("数据请求失败，前到后");
        }
    });
    return result;
}

function config_share(resobj) {
    $.ajax({
        url: magic_config.urlPrefix + 'WxOpenidService/getjsapiconfig',
        data: {
            url: window.location.href,
            storeId: "S4001"
        },
        type: 'post',
        success: function(res) {
            wx.config({
                debug: false,
                appId: res.response.appId, // 必填，公众号的唯一标识
                timestamp: res.response.timestamp, // 必填，生成签名的时间戳
                nonceStr: res.response.nonceStr, // 必填，生成签名的随机串
                signature: res.response.signature, // 必填，签名，见附录1
                jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage']
            });
        }
    });
    var _link = resobj.url;
    //_link = "www.baidu.com"
    wx.ready(function() {
        wx.onMenuShareTimeline({
            title: resobj.title,
            link: _link,
            imgUrl: resobj.picture,
            success: function() {},
            cancel: function() {}
        });

        wx.onMenuShareAppMessage({
            title: resobj.title,
            desc: resobj.content,
            link: _link,
            imgUrl: resobj.picture,
            success: function() {},
            cancel: function() {}
        });
    });
}
getShareinfo();